<extend name="Public/base"/>

<block name="body">
    <style type="text/css">
    div#upload_shows_field div {float: left; padding: 6px;}
    </style>
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
    <h2>
            <if condition="ACTION_NAME eq 'add'">
                新增商品
            <else/>
                编辑商品
            </if>
            <button class="btn btn-default btn-return" onclick="javascript:history.back(-1);return false;"><i class="glyphicon glyphicon-share-alt"></i> 返 回</button>
    </h2>        
    </div>
    
    <div class="tab-wrap">
            <ul class="tab-nav nav  nav-tabs">
                <li data-tab="tab1" class="current"><a href="javascript:void(0);">基本</a></li>
                <li data-tab="tab2" class=""><a href="javascript:void(0);">内容</a></li>
                <li data-tab="tab3" class=""><a href="javascript:void(0);">组图</a></li>
                <li data-tab="tab4" class=""><a href="javascript:void(0);">抽奖相关</a></li>
            </ul>
        <div class="tab-content"> 
            <form action="{:U()}" method="post" class="form">
            <div id="tab1" class="tab-pane in tab1">      
                <div class="form-item form-group">
                    <label class="item-label">商品名称<span class="check-tips"></span></label>
                    <div class="controls">
                        <input type="text" class="text form-control input-large" name="name" value="{$name}">
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">类型<span class="check-tips">(不能修改)</span></label>
                        <div class="controls">
                           <label class="radio-inline">
                            <input type="radio" value="exchange" name="type" checked> 兑换 
                        </label>
                        <label class="radio-inline">
                            <input type="radio" value="gamble" name="type"> 抽奖
                        </label>
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">虚拟实物<span class="check-tips"></span></label>
                        <div class="controls">
                           <label class="radio-inline">
                            <input type="radio" value="virtual" name="entity" checked> 虚拟 
                        </label>
                        <label class="radio-inline">
                            <input type="radio" value="real" name="entity"> 实物
                        </label>
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">使用积分<span class="check-tips">兑换或者抽奖需要的积分</span></label>
                    <div class="controls">
                        <input type="text" class="text form-control input-small" name="score" value="{$score}">
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">所属游戏</label>
                    <div class="controls">
                        <select class="form-control" name="game_id">
                            <option value="0">选择游戏</option>
                            <volist name="options.game" id="g">
                                <option value="{$key}">{$g}</option>
                            </volist>
                        </select>
                    </div>
                </div>
                
                <div class="form-item form-group">
                    <label class="item-label">状态<span class="check-tips"></span></label>
                    <div class="controls">
                        <label class="radio-inline">
                        <input type="radio" value="0" name="status" checked> 否 
                    </label>
                    <label class="radio-inline">
                        <input type="radio" value="1" name="status"> 是
                    </label>
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">是否精选<span class="check-tips"></span></label>
                    <div class="controls">
                        <label class="radio-inline">
                        <input type="radio" value="0" name="is_recomd" checked> 否 
                    </label>
                    <label class="radio-inline">
                        <input type="radio" value="1" name="is_recomd"> 是
                    </label>
                    </div>
                </div>

            </div>
            <div id="tab2" class="tab-pane tab2">
                <div class="form-item form-group">
                    <label class="item-label">描述<span class="check-tips"></span></label>
                    <div class="controls">
                    <label class="input-large">
                        <textarea class="form-control" rows="4" name="content">{$content|htmlspecialchars_decode}</textarea>
                    </label>
                    </div>
                </div>
                <div class="form-item form-group">
                    <label class="item-label">兑换流程<span class="check-tips">默认使用全局配置</span></label>
                    <div class="controls">
                    <label class="input-large">
                        <textarea class="form-control" rows="4" name="flow">{$flow|htmlspecialchars_decode}</textarea>
                    </label>
                    </div>
                </div>
                <div class="form-item form-group">
                    <label class="item-label">重要说明<span class="check-tips">默认使用全局配置</span></label>
                    <div class="controls">
                    <label class="input-large">
                        <textarea class="form-control" rows="4" name="explain">{$explain|htmlspecialchars_decode}</textarea>
                    </label>
                    </div>
                </div>
            </div>
            <div id="tab3" class="tab-pane tab3">
                <div class="form-item form-group">
                    <div class="controls">
                         <label class="item-label">组图<span class="check-tips">默认使用第一张作为封面 使用720*720等1:1的尺寸</span></label>
                        <input type="file" id="upload_shows">
                        <div id="upload_shows_field">
                            <notempty name="pics"> 
                                <volist name="pics" id="s">
                                    <div id="show_file_id_r{$key}">
                                        <div class="upload-img-box">
                                        <div class="upload-pre-item"><img src="__ROOT__{$s}"/></div>
                                        </div>
                                        <input type="hidden" name="pics[]" value="{$s}" />
                                        <br/>
                                        <a class="show_del" onclick="del_pic('r{$key}')">删除</a>
                                    </div>
                                </volist>
                            </notempty>
                        </div>
                        <div style="clear: both"></div>
                    </div>
                  
                    <script type="text/javascript">
                    //上传图片
                    /* 初始化上传插件 */
                    $("#upload_shows").uploadify({
                        "height"          : 30,
                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                        "fileObjName"     : "download",
                        "buttonText"      : "上传图片",
                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                        "width"           : 120,
                        'removeTimeout'   : 1,
                        'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                        "onUploadSuccess" : uploadPicture_shows,
                        'onFallback' : function() {
                            alert('未检测到兼容版本的Flash.');
                        }
                    });
                    function uploadPicture_shows(file, data){
                        var data = $.parseJSON(data);
                        var src = '';
                        if(data.status){
                            src = data.url || '__ROOT__' + data.path;
                            var html = '<div id="show_file_id_'+data.id+'"><div class="upload-img-box"><div class="upload-pre-item"><img src="'+src+'"/></div></div><input type="hidden" name="pics[]" value="'+src+'" /><br/><a class="show_del" onclick="del_pic(\''+data.id+'\')">删除</a></div>';
                            $('#upload_shows_field').append(html);
                        } else {
                            updateAlert(data.info);
                            setTimeout(function(){
                                $('#top-alert').find('button').click();
                                $(that).removeClass('disabled').prop('disabled',false);
                            },1500);
                        }
                    }
                    function del_pic(id) {
                        $('#show_file_id_'+id).remove();
                    }
                    </script>
                </div> 
            </div>

                <div id="tab4" class="tab-pane tab4">
                    <div class="form-item form-group">
                    <label class="item-label">奖品预算积分<span class="check-tips">( 计算概率使用, 公式:  中奖概率 = 使用积分/预算积分*(库存系数[库存/总数])*(个人系数[按照个人抽奖未中奖的次数梯级给出 1+logN 倍的奖励]); 个人最高概率不超过50%; 选择抽奖才有效 )</span></label>
                    <div class="controls">
                        <input type="text" class="text form-control input-small" name="gamble[prize_score]" value="{$gamble.prize_score}">
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">手动概率<span class="check-tips">( 如果不使用预算积分,则填写手动概率, 公式: 中奖概率 = 概率*(库存系数[库存/总数])*(个人系数[按照个人抽奖未中奖的次数梯级给出 1+logN 倍的奖励]);个人最高概率不超过50%; 选择抽奖才有效 )</span></label>
                    <div class="controls">
                        <input type="text" class="text form-control input-small" name="gamble[rate]" value="{$gamble.rate}">
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">是否有库存系数<span class="check-tips">关闭则不根据库存降低概率</span></label>
                    <div class="controls">
                        <label class="radio-inline">
                            <input type="radio" class="" name="gamble[is_stock_rate]" value="1">
                            是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" class="" name="gamble[is_stock_rate]" value="0">
                            否
                        </label>
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">是否有用户奖励<span class="check-tips">关闭则不根据用户抽奖次数进行概率提升</span></label>
                    <div class="controls">
                        <label class="radio-inline">
                            <input type="radio" class="" name="gamble[is_user_rate]" value="1">
                            是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" class="" name="gamble[is_user_rate]" value="0">
                            否
                        </label>
                    </div>
                </div>

                <div class="form-item form-group">
                    <label class="item-label">必中用户ID<span class="check-tips">如果设置了用户ID, 则该用户下一次抽奖必中; 每行一个</span></label>
                    <div class="controls">
                    <label class="input-large">
                        <textarea class="form-control" rows="4" name="gamble[red_users]">{$gamble.red_users}</textarea>
                    </label>
                    </div>
                </div>
                </div>

            </div>
            <div class="form-item form-group form-action">
                <input type="hidden" name="id" value="{$id}" />
                <button class="btn submit-btn ajax-post btn-success btn-block" id="submit" type="submit" target-form="form">确 定</button>
            </div>
        </form>
        </div>
    </div>
    
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('index')}');
        showTab();



        Think.setValue("type", '{$type|default="exchange"}');
        Think.setValue("entity", '{$entity|default="virtual"}');
        Think.setValue("status", '{$status|default=1}');
        Think.setValue("is_recomd", '{$is_recomd|default=0}');
        Think.setValue("game_id", '{$game_id|default=0}');
        Think.setValue("gamble[is_stock_rate]", '{$gamble.is_stock_rate|default=1}');
        Think.setValue("gamble[is_user_rate]", '{$gamble.is_user_rate|default=1}');
    </script>
</block>
